package com.example.test01;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public  class BroadCastAciivity extends MainActivity {
    Button but1;
    MyBroadCastReceiver myBroadCastReceiver;
    @Override
    public void onCreate(Bundle save) {
        super.onCreate(save);
        setContentView(R.layout.broadcastbutton);
        but1 = (Button) findViewById(R.id.send);
        regist();
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent();
                myIntent.setAction("ACTION");
                myIntent.putExtra("BroadCastMessage", "发送内容：123456");
                sendBroadcast(myIntent);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myBroadCastReceiver);
    }

    private void regist() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("ACTION");
        myBroadCastReceiver = new MyBroadCastReceiver();
        registerReceiver(myBroadCastReceiver, filter);
    }
}